package com.gzhu.knowledgeAdmin.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzhu.knowledgeAdmin.common.utils.UserInfoUtils;
import com.gzhu.knowledgeAdmin.dao.TRwjgjfTMapper;
import com.gzhu.knowledgeAdmin.entity.CheckResult;
import com.gzhu.knowledgeAdmin.entity.TRwjgjfT;
import com.gzhu.knowledgeAdmin.service.CheckResultService;
import com.gzhu.knowledgeAdmin.service.TRwjgjfTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class TRwjgjfTServiceImpl extends ServiceImpl<TRwjgjfTMapper, TRwjgjfT> implements TRwjgjfTService {

    @Autowired
    private CheckResultService checkResultService;

    @Override
    public List<TRwjgjfT> getUncheckDataSet() {

        String gsid = UserInfoUtils.getCurrentUser().getGsid();

        // 获取本公司的所有任务结果记录
        QueryWrapper<TRwjgjfT> wrapper = new QueryWrapper<>();
        wrapper.eq("F_GSID",gsid);
        wrapper.select("F_ID","F_RWNR");
        List<TRwjgjfT> allList = baseMapper.selectList(wrapper);

        Set<Long> allIdSet = allList.stream().map(TRwjgjfT::getFId).collect(Collectors.toSet());

        // 获取已经检测的记录
        List<CheckResult> checkResultList = checkResultService.getRecordByGsid(gsid);
        Set<Long> checkedIdSet = checkResultList.stream().map(CheckResult::getRwjgnrId).collect(Collectors.toSet());


        // 做差
        allIdSet.removeAll(checkedIdSet);

        return allList.stream().filter(item-> allIdSet.contains(item.getFId())).collect(Collectors.toList());



    }

    @Override
    public List<TRwjgjfT> getTaskTimeData() {
        return this.list(); // 或者根据你的实际需求进行查询
    }
}
